﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Popup EditForm 弹出表单编辑器</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" /><link href="../demo.css" rel="stylesheet" type="text/css" />

    
    <script src="../../scripts/boot.js" type="text/javascript"></script>
    
    <style type="text/css">

        
        .New_Button, .Edit_Button, .Delete_Button, .Update_Button, .Cancel_Button
        {
            font-size:11px;color:#1B3F91;font-family:Verdana;  
            margin-right:5px;          
        }
        
                
    </style>        
    <!-- Edit Form -->
    <script src="../CommonLibs/EditForm.js" type="text/javascript"></script>
</head>
<body>
    <h1>Popup EditForm 弹出表单编辑器</h1>      

    <div id="datagrid1" class="mini-datagrid" style="width:700px;height:280px;" 
        url="../data/AjaxService.jsp?method=SearchEmployees" allowResize="true" idField="id"
        
    >
        <div property="columns">
            <div name="action" width="120" headerAlign="center" align="center" renderer="onActionRenderer" cellStyle="padding:0;">#</div>
            <div field="loginname" width="120" headerAlign="center" allowSort="true">员工帐号
                <input property="editor" class="mini-textbox" />
            </div>                
            <div field="gender" width="100" allowSort="true" renderer="onGenderRenderer" align="center" headerAlign="center">性别
                
            </div>            
            <div field="age" width="100" allowSort="true">年龄
                
            </div>
            <div field="birthday" width="100" allowSort="true" dateFormat="yyyy-MM-dd">出生日期
                
            </div>                                    
            <div field="createtime" width="100" headerAlign="center" dateFormat="yyyy-MM-dd" allowSort="true">创建日期</div>                
        </div>
    </div>    
    
    
    <script type="text/javascript">
        var Genders = [{ id: 1, text: '男' }, { id: 2, text: '女'}];

        mini.parse();

       
        var grid = mini.get("datagrid1");
        grid.load();
        grid.sortBy("createtime", "desc");
        
        ///////////////////////////////////////////////////////       
        
        function onGenderRenderer(e) {
            for (var i = 0, l = Genders.length; i < l; i++) {
                var g = Genders[i];
                if (g.id == e.value) return g.text;
            }
            return "";
        }

        function onActionRenderer(e) {
            var grid = e.sender;
            var record = e.record;
            var uid = record._uid;
            var rowIndex = e.rowIndex;

            var s = '<a class="New_Button" href="javascript:newRow()">New</a>'
                    + '<a class="Edit_Button" href="javascript:editRow(\'' + uid + '\')">Edit</a>'
                    + '<a class="Delete_Button" href="javascript:delRow(\'' + uid + '\')">Delete</a>';
                       
            return s;
        }

        function newRow() {            
            var row = {};
            grid.addRow(row, 0);

            editRow(row._uid);
        }
        function editRow(row_uid) {
            var row = grid.getRowByUID(row_uid);
            if (row) {

                var editForm = mini.createTopSingle(EditForm);
                editForm.show();
                editForm.setData(mini_JSPath+"../../demo/data/AjaxService.jsp?method=GetEmployee&id=" + row.id,
                    function (action) {
                        if (action == "ok") {
                            var row = editForm.getData();
                            updateRow(row);
                        } else {
                            cancelRow();
                        }
                    }
                );
            }
        }
        function cancelRow() {
            grid.reload();

        }
        function delRow(row_uid) {
            var row = grid.getRowByUID(row_uid);
            if (row) {
                if (confirm("确定删除此记录？")) {
                    grid.loading("删除中，请稍后......");
                    $.ajax({
                        url: "../data/AjaxService.jsp?method=RemoveEmployees&id=" + row.id,
                        success: function (text) {
                            grid.reload();
                        },
                        error: function () {
                        }
                    });
                }
            }
        }

        function updateRow(o) {
            

            grid.loading("保存中，请稍后......");
            var json = mini.encode([o]);
            $.ajax({
                url: "../data/AjaxService.jsp?method=SaveEmployees",
                data: { data: json },
                success: function (text) {
                    grid.reload();
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    alert(jqXHR.responseText);
                }
            });            
        }
    </script>

    <div class="description">
        <h3>Description</h3>
        
    </div>
</body>
</html>